﻿using Engine;
using System.Collections.Generic;

namespace Game
{
    public static class BlockPixelDataDictionary
    {
        private static readonly Dictionary<string, Color> _colorGroups = new Dictionary<string, Color>
        {
            { "深灰色", new Color(67, 67, 67, 255) },
            { "中灰色", new Color(128, 128, 128, 255) },
            { "浅灰色", new Color(223, 223, 223, 255) },
            { "白色", new Color(255, 255, 255, 255) },
            { "棕色", new Color(135, 101, 55, 255) },
            { "绿色", new Color(37, 75, 9, 255) },
            { "红色", new Color(180, 0, 0, 255) },
            { "特殊色", new Color(88, 167, 255, 255) }
        };

        private static readonly Dictionary<string, List<int>> _indexGroups = new Dictionary<string, List<int>>
        {
            { "深灰色", new List<int> {0,1,3,5,36,38,40,134,135,137,138,139,140,141,142,143,144,145,146,150,151,152,155,156,157,179,180,181,182,183,184,185,186,187,188,196,209,214,218,222,224,231,237,253,254} },
            { "中灰色", new List<int> {6,8,12,13,14,16,18,39,41,46,48,53,54,57,58,64,65,66,67,72,84,87,95,96,101,112,136,148,154,189,190,193,194,202,217,225,226,229,232,233,243,248,256} },
            { "浅灰色", new List<int> {4,7,72,90,91,93,110,120,121,130,158,159,160,167,175,206,208,210,211,213,245,251,252} },
            { "白色", new List<int> {15,23,25,29,37,42,44,60,61,62,80,81,82,85,102,108,113,116,118,122,123,124,125,165,171,173,191,192,198,199,200,203,204,205,212,219,220,221,230,246} },
            { "棕色", new List<int> {2,9,10,11,17,21,27,28,45,47,49,51,52,55,56,59,63,68,69,70,73,74,75,76,83,86,94,97,98,99,100,105,106,107,115,117,131,132,133,147,153,166,168,170,177,178,207,216,227,234,235,236,238,242,244,255} },
            { "绿色", new List<int> {19,22,43,77,78,79,103,109,114,119,127,149,169,172,174,176,195,197,201,215,228,239,247,249,250} },
            { "红色", new List<int> {20,88,89,92,104,111,223,240} },
            { "特殊色", new List<int> {24,71,126,161,162,164,241} }
        };

        private static readonly HashSet<int> _envChangeIndexes = new HashSet<int> { 8, 12, 13, 14, 18, 225, 256 };

        public static Dictionary<int, BlockPixelData> GetBlockPixelDatas()
        {
            var result = new Dictionary<int, BlockPixelData>();

            foreach (var group in _indexGroups)
            {
                if (_colorGroups.TryGetValue(group.Key, out Color color))
                {
                    foreach (var index in group.Value)
                    {
                        result[index] = new BlockPixelData
                        {
                            BlockIndex = index,
                            Color = color,
                            NeedChangeWithEnvironment = _envChangeIndexes.Contains(index)
                        };
                    }
                }
            }

            return result;
        }
    }
}